<?php
$popular_food_name = "34534545 Tuna";
$popular_food_description = "A double layer of sear-sizzled 100% pure beef mingled with special sauce on a sesame seed bun and topped with melty American cheese, crisp lettuce, minced onions and tangy pickles.";
require ('mysqli_connect.php'); // Connect to the db.

function debug_to_console ($data)
{
    if (is_array($data))
        $output = "<script>console.log( 'Debug Objects: " . implode(',', $data) .
                 "' );</script>";
    else
        $output = "<script>console.log( 'Debug Objects: " . $data .
                 "' );</script>";
    
    echo $output;
}

//for dynamically displayin oferta_title
function display_oferta_details()
{
	    // Make the query:
    $type=$_REQUEST['type'];
    $value=$_REQUEST['value'];
	if ($type=='brand' && $value=='category')
	{
				$searchQuery=$value;
		//Displaying oferta_title
		echo '<div class="oferta_title">'. $searchQuery .'</div>';
		//The selected item is a Category and its definition
		echo '<div class="oferta_text">'. $searchQuery . ' is a very good Category</div>';
		echo '<a href="test.php?id=1234" class="details">Browse by ' . $searchQuery .'</a>';
	}
	else
	{
				$searchQuery=$value;
		//Displaying oferta_title
		echo '<div class="oferta_title">'. $searchQuery .'</div>';
		//The selected item is a Category and its definition
		echo '<div class="oferta_text">'. $searchQuery . ' is a very good Brand</div>';
		echo '<a href="test.php?id=1234" class="details">Browse by ' . $searchQuery .'</a>';
	}
} //End of display_oferta_details function.

  

// for adding the Brand Names
function list_results ()
{
    // Make the connection:
    $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
    
    // Set the encoding...
    mysqli_set_charset($dbc, 'utf8');
    // Make the query:
    $searchQuery=$_REQUEST['value'];
    //debug_to_console("Search Query-->". $searchQuery);
    
    $q = "select food_id,food_Name, brand_Name,image_url from nutrition_master where Food_Category like '%" . $searchQuery . "%' or food_name like '%".$searchQuery."%' or brand_Name like '%" . $searchQuery . "%' limit 1,9";
    $r = @mysqli_query ($dbc, $q); // Run the query.
    
    if ($r) { // If it ran OK, display the records.
    
        // Fetch and print all the records:
        while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
            
            $food_Name = $row['food_Name'];
            $brand_Name = $row['brand_Name'];
            $food_id = $row['food_id'];
            $image_url = $row['image_url'];
            
            echo '<div class="prod_box">
        	<div class="top_prod_box"></div>
            <div class="center_prod_box">
                 <div class="product_title"><a href="details.php?food_id='. $food_id.'">';
		echo $food_Name;
		echo '</a></div>
                 <div class="product_img"><a href="details.php?food_id='. $food_id.'"><img src="';
		echo $image_url;
                 echo'"   width="94" height="92" alt="" title="" border="0" /></a></div>
                 <div class="prod_price"><span class="price">';
			echo $brand_Name;
                 echo'</span></div>
            </div>
            <div class="bottom_prod_box"></div>
            <div class="prod_details_tab">

           <a href="details.php?food_id='. $food_id;
            echo '" class="prod_details">details</a>            
           </div>
        </div>';
        }
    
    
        mysqli_free_result ($r); // Free up the resources.
    
    } else { // If it did not run OK.
    
        // Debugging message:
        echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
    
    } // End of if ($r) IF.
    
    mysqli_close($dbc); // Close the database connection.

} // End of the function list_categories.




?>

<?php
include('header.php');
?>
    
    	<div class="left_content">
			<div class="title_box">Calories</div>
			<ul class="left_menu">
<?php
				for($calorie=1;$calorie<5000;)
				{
					debug_to_console("$calorie");
					echo '<li class="odd"><a href="advancedSearch.php?query='. $calorie. '">';
					//$calorieUp=$calorie+500;
        			echo $calorie. ' to  ';
					$calorie=$calorie + 499;
					echo $calorie;
					$calorie=$calorie + 1;// + 500;
					//$calorie=$calorieUp+1;
        			echo ' KCal</a></li>';
				}
				?>
            </ul>
            
             <div class="title_box">Newsletter</div>  
		     <div class="border_box">
				<input type="text" name="newsletter" class="newsletter_input" value="your email"/>
		        <a href="#" class="join">join</a>
		     </div> 
            
            
            <div class="banner_adds">
     			<a id="left_banner" href="#"><img src="../images/subway_banner.jpg" alt="" title="" border="0" /></a>
     		</div>   
		</div>

		</div>

		<div class="center_content">
			<div class="center_title_bar">Food Items</div>
 <?php list_results(); ?>
        </div>
		<!-- end of center content -->

		<div class="right_content">
			<div class="title_box">Price</div>
			<ul class="left_menu">
               <?php
				for($price=1;$price<50;)
				{
					debug_to_console("$price");
					echo '<li class="odd"><a href="advancedSearch.php?query='. $price. '">';
					//$calorieUp=$calorie+500;
        			echo $price. ' to  ';
					$price=$price + 4;
					echo $price;
					$price=$price + 1;// + 500;
					//$calorie=$calorieUp+1;
        			echo ' $ SGD</a></li>';
				}
				?>
            </ul>
            
            <div class="banner_adds">
     			<a id="right_banner" href="#"><img src="../images/subway_banner.jpg" alt="" title="" border="0" /></a>
     		</div> 
     	 <div class="banner_adds">
     			<a id="right_banner" href="#"><img src="../images/mcd_banner.jpg" alt="" title="" border="0" /></a>
     		</div>  
		</div>
		<!-- end of right content -->

<?php
include('footer.php');
?>